from lib.ZButton import ZButton
from lib.ZLoadJson import ZLoadJson
from lib.res.fun import _create_image
from resource.script.Skill.res.glo import _s_src


class Skill ( ZButton ) :
	def __init__ ( self , father , id ) :
		self.data = ZLoadJson ( _s_src [ 'data' ] [ id ] )
		self.id = id
		super ( Skill , self ).__init__ ( father , _create_image ( self.data.get ( ) [ 'icon' ] ) ,
		                                  _create_image ( self.data.get ( ) [ 'icon' ] ) , [ 40 , 40 ] )
		self.mp = self.data.get ( ) [ 'mp' ]

	def update ( self , event , mouse_pos , mouse_key ) :
		super ( Skill , self ).update ( event , mouse_pos , mouse_key )
		if self.isover ( mouse_pos , mouse_key ) :
			self.image.set_alpha ( 200 )
		else :
			self.image.set_alpha ( 255 )

	def _action ( self ) :
		from resource.ui.sces import players
		if players [ 0 ].mp <= 0 :
			print "No Mana!!!!"
		else :
			if self.id == 0 :
				if players [ 0 ]._hit_mp ( self.mp ) :
					from resource.script.Map.lib.Map import block_data
					for x in block_data :
						for y in block_data [ x ] :
							block = block_data [ x ] [ y ]
							if block.status == 2 :
								if block.type == 2 :
									block.enemy.ad = 1
			if self.id == 1 :
				if players [ 0 ]._hit_mp ( self.mp ) :
					players [ 0 ]._add_hp ( 15 )
			if self.id == 2 :
				if players [ 0 ]._hit_mp ( self.mp ) :
					players [ 0 ]._add_buff ( 0 , self.data.get ( ) [ 'time' ] )
					players [ 0 ].ad += 3
